<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/include/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
	<table id="dg" class="easyui-datagrid" title="用户管理" style="width:705px;height:250px"
			url="${ctx}/user/list.do"
			pagination="true"
            rownumbers="true" 
            fitColumns="true" 
            singleSelect="true"
            data-options="toolbar:toolbar">
			<thead>
				<tr>
					<th data-options="field:'id',width:80">编号</th>
					<th data-options="field:'entity.name',width:100">姓名</th>
					<th data-options="field:'entity.phone',width:100">电话</th>
					<th data-options="field:'entity.email',width:100">Email</th>
					<th data-options="field:'entity.role',width:80,align:'right'">角色</th>
				</tr>
			</thead>
	</table>
	<script type="text/javascript">
		var actionUrl;
		var toolbar = [{
			text:'添加',
			iconCls:'icon-add',
			handler:function(){
				$("input[name='entity.id']").val("");
				actionUrl="${ctx}/user/saveOrUpdate.do";
				$("#dlg").dialog('open').dialog('setTitle','添加用户');
				$('#fm').form('clear');
			}
		},
		{
			text:'编辑',
			iconCls:'icon-edit',
			handler:function(){
				var row=$('#dg').datagrid('getSelected');
				if(row){
					$("input[name='entity.id']").val(row.id);
					actionUrl='${ctx}/user/saveOrUpdate.do';
					$("#dlg").dialog('open').dialog('setTitle','编辑用户');
					$('#fm').form('load',row);
				}
			}
		},
		{
			text:'删除',
			iconCls:'icon-remove',
			handler:function(){
				var row=$('#dg').datagrid('getSelected');
				if(row){
					$.messager.confirm("系统提示","您确定要删除这条记录吗?",function(r){
						if(r){
							$.post('${ctx}/user/delete.do',{'entity.id':row.id},function(result){
								if(result.success){
									$.messager.alert("系统提示",result.msg);
									$("#dg").datagrid("reload");
								}else{
									$.messager.alert("系统提示",result.msg);
								}
							},'json');
						}
					});
				}
			}
		}];
		
		
		function saveUser(){		
			$('#fm').form({
				url:actionUrl,
				onSubmit:function(){
					return $(this).form('validate');
				},
				success:function(result){
					var result=eval('('+result+')');
					if(result.success){
						$.messager.alert("系统提示",result.msg);
						$('#dlg').dialog('close');
						$("#dg").datagrid("reload");
					}else{
						$.messager.alert("系统提示",result.msg);
						return;
					}
				}
			});
			$('#fm').submit();
		}
	</script>
	
	
	<div id="dlg" class="easyui-dialog" style="width:400px;height:250px;padding:10px 20px" closed="true" buttons="#dlg-buttons">
	        <form id="fm" method="post" >
	        	<input type="hidden" name="entity.id" />
	        	<table cellspacing="10px;">
	        		<tr>
	        			<td>姓名：</td>
	        			<td><input name="entity.name" class="easyui-validatebox" required="true" style="width: 200px;"></td>
	        		</tr>
	        		<tr>
	        			<td>联系电话：</td>
	        			<td><input name="entity.phone" class="easyui-validatebox"  style="width: 200px;"></td>
	        		</tr>
	        		<tr>
	        			<td>Email：</td>
	        			<td><input name="entity.email" class="easyui-validatebox" validType="email" style="width: 200px;"></td>
	        		</tr>
	        		<tr>
	        			<td>角色：</td>
	        			<td><input name="entity.role" class="easyui-validatebox" validType="role" style="width: 200px;"></td>
	        		</tr>
	        		<tr>
	        			<td>语言：</td>
	        			<td><input class="easyui-combobox" 	name="language"	
			        	   			data-options="
			        	   				url:'${ctx}/pages/easyui/user/data.json',
										valueField:'id',
										textField:'text',
										panelHeight:'auto'
										">	
						</td>
	        		</tr>
	        		
	        		
	        	</table>
	        </form>
	</div>
	<div id="dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
	</div>
</body>
</html>
